<% layout('/layouts/default.html', {title: '文件领取', libs: ['dataGrid']}){ %>
<style>
    .camera{
        height: 30px;
        background-color: #ffffff;
        border-color: #1E5EDB;
        color: #1E5EDB;
    }

</style>
<div class="form-group"  >
    <div class="row">
    <div class="col-sm-8">
        <div class="form-group">
            <!--<div class="box-tools pull-left" style="margin-left: 5px;">
                <a href="#" style="margin-right: 20px;background-color: #133b8a;color: white" class="btn btn-default"    onclick="lin(0)" id="zheng" title="${text('领文')}"><i class=" "></i> ${text('正常领文')}</a>
                <a href="#"  class="btn btn-default"   id="lin"  onclick="lin(1)" title="${text('临时领文')}"><i class=" "></i> ${text('临时领文')}</a>

            </div>-->

            <!--
           <label class="control-label col-sm-4" title="">

                <span class="required hide" aria-required="true">*</span> 临时领文：<i
                    class="fa icon-question hide"></i></label>
            <input type="radio" name="radio_name" onclick="ye()" id="yes" class="" value="1"
                   checked="checked"> 是
            <input type="radio" name="radio_name" onclick="fo()" id="fou" class="" value="0">-->
        </div>


    </div>
    </div>
    <form id="inputForm"  action="${ctx}/sd/docDeliverRecord/takeFiles" method="post">
       <div class="box box-main"  style="margin-top: 2%;">



        <#form:input path="lingwen" id="lw" maxlength="100" class="form-control "  type="hidden"  />
        <#form:input path="facePath" id="pictureSrc" maxlength="100" class="form-control  " type="hidden" />
        <div class="row " style="margin-bottom: 88px;margin-top: 2%">
            <div class="col-xs-3 " id="office">
                <div class="form-group">
                    <label class="control-label col-sm-4">${text('单位选择')}：</label>
                    <div class="col-sm-8">
                        <#form:treeselect id="testOffice" title="单位选择" name="ted"
                        path="officeCode" labelPath="testOffice.officeCode"
                        url="${ctx}/sys/office/treeData"  allowClear="true"  callbackFuncName="selectfileunit" />
                    </div>
                </div>
            </div>

            <div >
                <div class="col-xs-2">
                    <div class="form-group">
                        <label class="control-label col-sm-4">${text('姓名')}：</label>
                        <i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:input path="userName"  labelPath="userName" id="xm" maxlength="100" class="form-control " />
                        </div>
                    </div>
                </div>
                <div class="col-xs-2">
                    <div class="form-group">

                        <label class="control-label col-sm-4">${text('警号')}：</label>
                        <i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:input path="extendS1" id="jx" maxlength="100" class="form-control  " />

                        </div>
                    </div>
                </div>
                <div class="col-xs-3">
                    <div class="form-group">

                        <label class="control-label col-sm-4">${text('操作员密码')}：</label>
                        <i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:input path="userId" id="userId" type="password" autocomplete="new-password"  maxlength="100" class="form-control " placeholder="当前登录人密码" />

                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-5" style="position: absolute;right: -250px;top: -30px;">
                <div class="form-group">
                    <label class="control-label col-sm-2">
                    </label>
                    <div class="col-sm-8">

                          <img  id="showImg" style="width: 150px;border-radius: 50%;cursor: pointer" class="img-responsive"  src="${ctxStatic}/camera.jpg" class="img-responsive" title="领文人拍照" onclick="collectPicture()">
                    </div>
                </div>
            </div>

        </div>
       </div>
      <!--  <div class="row" id="nolinshi" >
            <div class="col-xs-4">
                <div class="form-group ">
                    <label class="control-label col-sm-4">${text('领文人选择')}：</label>
                    <i class="fa icon-question hide"></i></label>
                    <div class="col-sm-8">
                        <#form:treeselect  title="用户选择" path="userCode" labelPath="testUser.userCode"
                        url="${ctx}/sd/docDeliverWaitTake/treeData?isLoadUser=true"    callbackFuncName="selectfile" id="testUser"/>

                    </div>
                </div>
            </div>-->

            <!--<div class="col-xs-2">
                <div class="form-group">
                    <label class="control-label col-sm-2">
                    </label>
                    <div class="col-sm-8">
                        <a href="#" class="btn btn-default camera"   title="录入人脸" onclick="collectPicture()"><i class="icon-camera"></i></a>
                    </div>
                </div>
            </div>-->
        </div>




        <div class="box-footer hidden">
            <div class="row ">
                <div class="col-sm-offset-2 col-sm-10" >
                    <% if (hasPermi('sd:docDeliverRecord:edit')){ %>
                    <button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}
                    </button>&nbsp;
                    <% } %>
                    <button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
                </div></div>
        </div>


</form>
</div>
<div class="ml10 mr10">
    <h4 class="form-unit">${text('文件信息列表')}</h4>
    <table id="dataGrid"></table>
    <form id="searchForm"  action="${ctx}/sd/docDeliverTake/selectFileUnit">

    </form>
</div>



<%}%>



<script>
   var facepath;
    //
    // function show(){
    //     js.layer.alert("<img src="+facepath+">")
    //
    // }
    function selectfileunit(id, act, index, layero, nodes) {
        $("#dataGrid").html("")
        if (id == 'testOffice' && (act == 'ok' || act == 'clear')){
            var win = layero.iframeWindow();
            // log(win);    // 选择框内容的window对象
            // log(act);    // 回调活动事件（ok、clear、cancel）
            // log(index);  // layer的index
            // log(layero); // layer实例对象
            // log(selectData);  // 选择的节点数据
            var id=nodes[0].id;  // 选择的节点数据

           $.ajax({
                type: "GET",
                url: "${ctx}/sd/docDeliverTake/selectFileUnit?offId="+id,
                contentType: false,
                processData: false,
                success: function (data) {
                    if(data.result===Global.TRUE){
                        console.log(data)
                        js.layer.msg(data.message, {icon: 1})
                        var info= data.data;
                        for(var i=0;i<info.length;i++){
                            $('#dataGrid').jqGrid('addRow', {
                                position: 'last',
                                addRowParams: {keys: true, focusField: true},
                                initdata: {
                                    idd: info[i].docId,
                                    fileTitle: info[i].docRecv.docTitle,
                                    takeUnitName: info[i].office.officeName,

                                }
                            });
                        }


                    }else{
                        $("#testUserCode").val("")
                        $("#testOfficeCode").val("")
                        $("#testUserName").val("")
                        $("#testOfficeName").val("")
                        js.layer.msg(data.message, {icon: 5})

                    }

                }
            })
            return true;
        }



    }


    // 初始化DataGrid对象
    $('#dataGrid').dataGrid({
        // 查询数据表单
        searchForm: $('#searchForm'),
        showRownum: false,
        // 设置数据表格列
        columnModel: [
            {header:'文件编号', name:'idd' },
            {header:'文件标题', name:'fileTitle'},
            {header:'来文单位', name:'takeUnitName'},

        ],
        // 加载成功后执行事件
        ajaxSuccess: function(data){

        }
    });


   /*function rese(){
       js.layer.confirm("<div> <img src="+facepath+"  style='height: 300px;'> </div>",{
           title : "预览照片",
           skin : "my-skin",
           btn : [ '重拍', '取消' ],
           yes:function (index) {
               collectPicture();
           }

       })

   }*/



    window.onload = function () {
        $("#linshi").css("display", "none");
        $("#lw").val("1")
    }

    function collectPicture(){
            js.layer.open({
                type: 2,
                area: [(js.layer.window.outerWidth-350)+'px',(js.layer.window.outerHeight-200)+'px'],
                title: '${text("拍照")}',
                resize: false,
                scrollbar: true,
                maxmin:true,
                content: '${ctx}/sd/collectPicture/form',
                success: function(layero, index){

                },
                btn: ['<i class="fa fa-check"></i> ${text("上传")}',
                    '<i class="fa fa-remove"></i> ${text("关闭")}'],
                btn1: function (index, layero) {
                    var win = layero.iframeWindow();
                    if (typeof(win.getFile()) == "undefined"){
                        js.layer.msg('请先拍照再提交!', {icon: 5});
                        return false;
                    }
                    console.log(typeof (win.getFile()));
                    var formData = new FormData;
                    formData.append("file", win.getFile());
                    $.ajax({
                        type: "POST",
                        url: "${ctx}/sd/collectPicture/uploadFile",
                        data: formData,
                        contentType: false,
                        processData: false,
                        success: function (data) {
                            if(data.result===Global.TRUE){
                                js.layer.msg(data.message, {icon: 1});
                                js.layer.close(index);
                                $('#pictureSrc').val(data.data);
                                facepath=win.getUrl();
                                $("#showImg").attr("src",facepath)
                              //  $("#showImg").attr("onclick","rese()");
                                return true;
                            }else {
                                js.layer.msg(data.message, {icon: 5});
                                return false;
                            }

                        }
                    })
                    return false;

                }


            });
        }






</script>







